<?php
$db = $this->db;
$r = $_SESSION[USUARIO];
$userName = sqlValue($r["usuario"], "text");
$opciones = "select cllg_menu.TITTLE,cllg_menu.ID from cllg_acces,cllg_menu,cllg_user,cllg_perfil
where cllg_user.USER_NAME = $userName
 and cllg_user.FK_PERFIL = cllg_acces.FK_PERFIL
 and cllg_acces.FK_MENU = cllg_menu.ID
 and cllg_acces.status=1
 and cllg_menu.ORDEN = 0 group by cllg_menu.id";

$rsOpciones = $db->queryToArray($opciones);
?>
    <ul class="jd_menu">
        <?php
        foreach ($rsOpciones as $opcion) {
            $id = $opcion["ID"];
        ?>
            <li  class="accessible"><a  class="accessible"  title="<?php echo $opcion["TITTLE"]; ?>" href="#">
			<?php echo $opcion["TITTLE"]; ?>&nbsp; &raquo;</a>
            <?PHP
            $querySubOpciones = "select cllg_menu.URL,cllg_menu.TITTLE,cllg_menu.ID,cllg_menu.MENU_PARENT
                                                                    from
                                                                    (select * from cllg_acces a where a.status=1) acces,cllg_menu,cllg_user,cllg_perfil
                                                                    where cllg_user.USER_NAME like $userName
                                                                    and cllg_user.FK_PERFIL = acces.FK_PERFIL
                                                                    and cllg_menu.ID = acces.FK_MENU
                                                                    and cllg_menu.ORDEN = '$id'
                                                                    and cllg_menu.MENU_PARENT <= 2 group by cllg_menu.id";
            $rsSubOpciones = $db->queryToArray($querySubOpciones); ?>
            <ul>
                <?php
                foreach ($rsSubOpciones as $subOpcion) {
                    if ($subOpcion["MENU_PARENT"] >= 2) {
                        $Subsuba = "SI";
                    } else {
                        $Subsuba = "NO";
                    }
                ?>
                <?PHP if ($Subsuba == "NO") {
                ?>
                        <li><a href="javascript:load('<?php echo $subOpcion["URL"]; ?>')"><?php echo $subOpcion["TITTLE"]; ?></a></li>
                <?PHP } ?>
                <?PHP if ($Subsuba == "SI") {
                ?>
                        <li><a class="parent" href="#"><?PHP echo $subOpcion["TITTLE"]; ?></a>
                    <?PHP
                        $idmenu = $subOpcion["ID"];
                        $Querry_recordSetSUb = "select *
                                    from cllg_menu,cllg_user,(select * from cllg_acces a where a.status=1) acces
                                    where cllg_user.USER_NAME like $userName
                                          and cllg_user.FK_PERFIL = acces.FK_PERFIL
                                          and cllg_menu.ID = acces.FK_MENU
                                          AND ORDEN = '$idmenu'";
                        $recordsetSUb = $db->queryToArray($Querry_recordSetSUb);
                    ?>
                        <ul>
                        <?PHP foreach ($recordsetSUb as $pruebaSUb) {
                        ?>
                            <li><a href="javascript:load('<?php echo $pruebaSUb["URL"]; ?>')" > <?PHP echo $pruebaSUb["TITTLE"]; ?></a></li>
                        <?PHP } ?>
                    </ul>
                </li>
                <?PHP } ?>
                <?PHP } ?>
            </ul>
        </li>
        <?PHP
            }
        ?>
    </ul>


